package day03;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**2018-03-25
 * 输入一个生产日期格式"yyyy-MM-dd",再输入一个数字(保质期的天数)。
 * 然后经过计算输出促销日期，促销日期为:该商品过期日前2周的周三
 * @author Bonnie
 * 
 */
public class Test04 {
    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入生产日期(格式：yyyy-MM-dd):");
        String out = scanner.next();
        System.out.print("请输入保质天数:");
        int days = scanner.nextInt();
        Calendar cal = Calendar.getInstance();
        try {
            cal.setTime(sdf.parse(out));
        } catch (ParseException e) {
            System.out.println("输入日期有误!!");
        }
        cal.add(Calendar.DAY_OF_YEAR, days - 14);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.WEEK_OF_MONTH);
        Date sale = cal.getTime();
        System.out.println("促销日期为: " + sdf.format(sale));

    }
	
}
